﻿
using Puerts;

public class ABC
{
    public static void TryA(object obj)
    {
        var bb = (Puerts.ArrayBuffer)obj;
        bb.Bytes[0] = 0;
        bb.Bytes[1] = 1;
        bb.Bytes[2] = 2;
        bb.Bytes[3] = 33;
    }
    public static void TryB(int a, int b, int c, int d)
    {

    }

}

namespace purets_test0
{
    class ME : Puerts.JsEnv
    {

    }


    internal class Program
    {
        static void _callcs(IntPtr isolate, IntPtr info, IntPtr self, int paramLen, long data)
        {
            var type = PuertsDLL.GetArgumentType(isolate, info, 0, false);
            var v1 = PuertsDLL.GetArgumentValue(info, 0);
            var p1 = (int)PuertsDLL.GetNumberFromValue(isolate, v1, false);
            if (p1 == 1)
            {
                var value = PuertsDLL.GetArgumentValue(info, 1);
                var ptr = PuertsDLL.GetArrayBufferFromValue(isolate, value, out int length, false);
                unsafe
                {
                    byte* u8ptr = (byte*)ptr;

                    u8ptr[0] = 1;
                    u8ptr[1] = 245;
                    u8ptr[3] = 44;
                }
            }
            else
            {
                var v2 = PuertsDLL.GetArgumentValue(info, 1);
                var v3 = PuertsDLL.GetArgumentValue(info, 2);
                var v4 = PuertsDLL.GetArgumentValue(info, 3);
                var v5 = PuertsDLL.GetArgumentValue(info, 4);
                var vv2 = PuertsDLL.GetNumberFromValue(isolate, v2, false);
                var vv3 = PuertsDLL.GetNumberFromValue(isolate, v3, false);
                var vv4 = PuertsDLL.GetNumberFromValue(isolate, v4, false);
                var vv5 = PuertsDLL.GetNumberFromValue(isolate, v5, false);
            }
        }
        static void Main(string[] args)
        {
            Puerts.JsEnv jsenv = new Puerts.JsEnv(new DefaultLoader(), 50443);
            PuertsDLL.SetGlobalFunction(jsenv.GetIsolate(), "_callcs", _callcs, 788);
            //jsenv.UsingAction<float>();
            //PuertsStaticWrap.AutoStaticCodeRegister.Register(jsenv);
            jsenv.Eval(@"
let u8 =new Uint8Array(64);
_callcs(1,u8);
_callcs(2,u8[0],u8[1],u8[2],u8[3]);
");

            //TT._Update();

            //while (true)
            //{
            //    jsenv.Tick();
            //    System.Threading.Thread.Sleep(100);
            //    TT._Update();
            //}
        }
    }
}